package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.redp.bizimpl.bean.LabelValueBean;
import cc.rengu.redp.bizimpl.constant.UpmpConstant;
import cc.rengu.redp.bizimpl.enums.*;
import cc.rengu.redp.bizimpl.igas.service.PTxnCfgService;
import cc.rengu.redp.bizimpl.igas.vo.PTxnAuthMap;
import cc.rengu.redp.bizimpl.igas.vo.PTxnGroup;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.dao.BProdInfoMapper;
import cc.rengu.redp.bizimpl.upmp.domain.*;
import cc.rengu.redp.bizimpl.upmp.service.*;
import cc.rengu.redp.bizimpl.upmp.vo.OperationResult;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.Common;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.bizimpl.utils.DateUtils;
import cc.rengu.redp.bizimpl.utils.RedpUpmpUtil;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import cc.rengu.redp.common.utils.DateUtil;
import cc.rengu.redp.common.utils.SortUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;
/*
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘玉亮.LL
 * @since 2021-06-10
 */


@Service
public class BProdInfoServiceImpl extends ServiceImpl<BProdInfoMapper, BProdInfo> implements IBProdInfoService {
    @Autowired
    private IBizTmpService bizTmpService;
    @Autowired
    IUpmpPrivilegeCheckService privilegeCheckService;
    //    @Autowired
//    private IUpmpOrganizationService organizationService;
    @Autowired
    private IBProdFeeInfoService bProdFeeInfoService;
    @Autowired
    private IBProdStageInfoService bProdStageInfoService;
    /**
     * 查询时使用
     */
    @Autowired
    private IBProdAuthCtrlService bProdAuthCtrlService;
    @Autowired
    private IUpmpSysParamService upmpSysParamService;


    @Autowired
    private IBBaseProdInfoService bBaseProdInfoService;
    @Autowired
    private PTxnCfgService pTxnCfgService;

    @Autowired
    private IUpmpPrivilegeCheckService upmpPrivilegeCheckService;

    private String oprMenuId = "20000017";
    private String oprMenuName = "产品管理:标准产品管理";
//    private String oprBtnNamePrefix = "标准产品管理";
    private String oprBtnNamePrefix = "standardProducts";
    private String webNextUrl = "/admin/mcmp/bProdInfo/getSubList";

    @Override
    public String getOprMenuId() {
        return oprMenuId;
    }

    @Override
    public String getOprMenuName() {
        return oprMenuName;
    }

    @Override
    public String getWebNextUrl() {
        return webNextUrl;
    }

    @Override
    public String getOprBtnNamePrefix() {
        return oprBtnNamePrefix;
    }

    @Override
    public IPage<BProdInfo> findByPage(QueryRequest request, BProdInfo info) {
        try {
            LambdaQueryWrapper<BProdInfo> queryWrapper = new LambdaQueryWrapper<>();
            if (StringUtils.isNotBlank(info.getInstId())) {
                queryWrapper.eq(BProdInfo::getInstId, info.getInstId());
            }
            if (StringUtils.isNotBlank(info.getProdStatus())) {
                queryWrapper.eq(BProdInfo::getProdStatus, info.getProdStatus());
            }
            if (StringUtils.isNotBlank(info.getAuditStatus())) {
                queryWrapper.eq(BProdInfo::getAuditStatus, info.getAuditStatus());
            }
            queryWrapper.ne(BProdInfo::getProdStatus,"M");
            Page<BProdInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.baseMapper.findByPage(page, queryWrapper, info);
        } catch (Exception e) {
            log.error("查询失败", e);
            return null;
        }
    }

    @Override
    public IPage<BProdInfo> findAddProdInfoSubByPage(QueryRequest request, BProdInfo info) {
        try {
            LambdaQueryWrapper<BProdInfo> queryWrapper = new LambdaQueryWrapper<>();
            if (StringUtils.isBlank(info.getInstId())) {
                UpmpSysParam defaultInst = upmpSysParamService.getById(UpmpConstant.DEAFULT_INST_PARAM_ID);
                UpmpUserInfoVO currentUser = RedpUpmpUtil.getCurrentUser(defaultInst.getPrimaryValue());
                info.setInstId(currentUser.getInstId());
            }
            if (StringUtils.isBlank(info.getProdCode())) {
                info.setProdCode("ERR");
            }
            Page<BProdInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.baseMapper.findAddProdInfoSubByPage(page, queryWrapper, info);
        } catch (Exception e) {
            log.error("查询失败", e);
            return null;
        }
    }

    @Override
    public IPage<BProdInfo> findChckProdInfoSubByPage(QueryRequest request, BProdInfo info) {
        try {
            LambdaQueryWrapper<BProdInfo> queryWrapper = new LambdaQueryWrapper<>();
            if (StringUtils.isBlank(info.getInstId())) {
                UpmpSysParam defaultInst = upmpSysParamService.getById(UpmpConstant.DEAFULT_INST_PARAM_ID);
                UpmpUserInfoVO currentUser = RedpUpmpUtil.getCurrentUser(defaultInst.getPrimaryValue());
                info.setInstId(currentUser.getInstId());
            }
            if (StringUtils.isBlank(info.getProdCode())) {
                info.setProdCode("ERR");
            }
            if (StringUtils.isBlank(info.getAuditStatus())) {
                throw new RedpException("审核状态不能为空");
            }
            Page<BProdInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.baseMapper.findChckProdInfoSubByPage(page, queryWrapper, info);
        } catch (Exception e) {
            log.error("查询失败", e);
            return null;
        }
    }

    @Override
    public IPage<BProdInfo> findUpdProdInfoSubByPage(QueryRequest request, BProdInfo info) {
        try {
            LambdaQueryWrapper<BProdInfo> queryWrapper = new LambdaQueryWrapper<>();
            if (StringUtils.isBlank(info.getInstId())) {
                UpmpSysParam defaultInst = upmpSysParamService.getById(UpmpConstant.DEAFULT_INST_PARAM_ID);
                UpmpUserInfoVO currentUser = RedpUpmpUtil.getCurrentUser(defaultInst.getPrimaryValue());
                info.setInstId(currentUser.getInstId());
            }
            Page<BProdInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.baseMapper.findUpdProdInfoSubByPage(page, queryWrapper, info);
        } catch (Exception e) {
            log.error("查询失败", e);
            return null;
        }
    }

    @Override
    public BProdInfo findProdByUK(String instId, String prodCode, String baseProdCode) {
        LambdaQueryWrapper<BProdInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BProdInfo::getInstId, instId);
        wrapper.eq(BProdInfo::getProdCode, prodCode);
        wrapper.eq(BProdInfo::getBaseProdCode, baseProdCode);
        return this.getOne(wrapper);
    }


    @Override
    public BProdInfo findProdByDistinct(String instId, String prodCode) {
        LambdaQueryWrapper<BProdInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BProdInfo::getInstId, instId);
        wrapper.eq(BProdInfo::getProdCode, prodCode);
        List<BProdInfo> list = this.list(wrapper);
        return list.get(0);
    }

    @Override
    public List<BProdInfo> findProdByCode(String instId, String prodCode) {
        LambdaQueryWrapper<BProdInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BProdInfo::getInstId, instId);
        wrapper.eq(BProdInfo::getProdCode, prodCode);
        return this.list(wrapper);
    }

    @Override
    public String getNewProdCode(String instId) {
        String prodCode = String.format("%02d", (Integer) (this.baseMapper.getMaxProdCode(instId) == null ? 1 : this.baseMapper.getMaxProdCode(instId)));
        return prodCode;
    }

    @Override
    public Map<String, Object> getSubList(BProdInfo entity) throws RedpException {
        Map<String, Object> result = new HashMap<>();
        String optFlag = entity.getOptFlag();
        String instId = entity.getInstId();
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            entity = new BProdInfo();
            entity.setInstId(instId);
            entity.setProdCode(this.getNewProdCode(instId));
        } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)) {
            entity = this.getById(entity.getId());
        } else {
            //注销 详情
            entity = this.findProdByDistinct(entity.getInstId(), entity.getProdCode());
        }
        entity.setOptFlag(optFlag);
        //审核时线上临时表的标准产品信息
        if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)) {
//            BizTmp bizTmp = bizTmpService.getById(entity.getId());
//            String json = bizTmp.getBizData1() + bizTmp.getBizData2() + bizTmp.getBizData3();
//            BProdInfo temp = JSON.parseObject(json, BProdInfo.class);
            BProdInfo temp = bizTmpService.getObjFromBizTmp(entity.getId(), BProdInfo.class);
            temp.setOptFlag(entity.getOptFlag());
            List<LabelValueBean> compareBeans = CommonUtils.compareData(temp, entity, BProdInfo.class);
            result.put("compareBeans", JSON.toJSONString(compareBeans));
            result.put("entity", temp);
            result.put("entityReal", entity);
        } else {
            result.put("entity", entity);
        }
        return result;
    }

    @Override
    public Map<String, Object> getEdit(BProdInfo entity) throws RedpException {
        Map<String, Object> result = new HashMap<>();
        if (!PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag())) {
            if (Common.isBlank(entity.getInstId())) {
                log.error("法人行行号为空！");
                throw new RedpException("法人行行号为空!");
            }
            BProdInfo bProdInfo;
            if (Common.isBlank(entity.getProdCode())) {
                log.error("标准产品编号为空！");
                throw new RedpException("标准产品编号为空!");
            } else {
                //这里没有直接去检测输入的标准产品编码是否存在是因为点击第一个基础产品的配置后数据入库，再点其他基础产品配置时就已经存在这个标准产品的数据了
                bProdInfo = this.findProdByUK(entity.getInstId(), entity.getProdCode(), entity.getBaseProdCode());
                if (Common.isBlank(bProdInfo)) { //如果没有查到 bProdInfo 则认为是新增，去取基础产品编码对应的产品信息

                    BBaseProdInfo baseProd = bBaseProdInfoService.findByUK(entity.getInstId(), entity.getBaseProdCode());
                    if (Common.isBlank(baseProd)) {
                        log.error("法人行行号[" + entity.getInstId() + "],基础产品编码[" + entity.getBaseProdCode() + "]没有查询到基础产品数据！");
                        throw new RedpException("法人行行号[" + entity.getInstId() + "],基础产品编码[" + entity.getBaseProdCode() + "]没有查询到基础产品数据！");
                    }
                    bProdInfo = new BProdInfo();
                    bProdInfo.setInstId(entity.getInstId());
                    bProdInfo.setBaseProdCode(entity.getBaseProdCode());
                    bProdInfo.setBaseProdName(entity.getBaseProdName());
                    bProdInfo.setBaseProdDesc(entity.getBaseProdDesc());
                    bProdInfo.setProdCode(entity.getProdCode());
                    bProdInfo.setProdName(entity.getProdName());
                    bProdInfo.setProdDesc(entity.getProdDesc());
                    bProdInfo.setWechatChannelId(baseProd.getWechatChannelId());
                    bProdInfo.setAlipayChannelId(baseProd.getAlipayChannelId());
                    bProdInfo.setOptFlag(entity.getOptFlag());

                  /*          // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
                    UpmpOrganization org = organizationService.getOrgByUser(user, bProdInfo.getInstId());
                    if (Common.isBlank(org)) {
                        log.error("根据用户信息获取的机构号为空！");
                        throw new RedpException("根据用户信息获取的机构号为空!");
                    }*/
                    //基础产品费率
                    List<BProdFeeInfo> feeInfos = bProdFeeInfoService.getBaseProdFeeList(entity.getInstId(), ProdTypeEnum.BASE_PROD.getType(), entity.getBaseProdCode());

                    if (CollectionUtils.isNotEmpty(feeInfos)) {
                        for (BProdFeeInfo fee : feeInfos) {
                            //对基础产品的费率改成标准产品并脱管
                            fee.setInstId(entity.getInstId());
                            //fee.setProdType(ProdTypeEnum.PROD.getType());
                            fee.setProdCode(entity.getProdCode());
                        }
                    }
                    //基础产品交易大类、交易(全量交易)
                    List<PTxnGroup> txnGroups = this.findPTxnGroupByList(entity.getInstId(), ProdTypeEnum.BASE_PROD.getType(), entity.getBaseProdCode());
                    List<BProdAuthCtrl> selectedTxnNums = bProdAuthCtrlService.getBaseProdAuthCtrl(entity.getInstId(), ProdTypeEnum.BASE_PROD.getType(), entity.getBaseProdCode());

                    if (CollectionUtils.isNotEmpty(txnGroups)) {
                        Map<String, String> map = upmpSysParamService.findMapDataByPrimaryKey(BusinessContainer.SYS_TXN_GROUP_PARAM, entity.getInstId(), null);
                        for (PTxnGroup pTxnGroup : txnGroups) {
                            pTxnGroup.setTxnGroupName(map.get(pTxnGroup.getTxnGroup()));
                            //获取当前交易大类下的所有交易小类
                            List<PTxnAuthMap> pTxnAuthMaps = pTxnGroup.getpTxnAuthMaps();
                            if (Common.isNotBlank(selectedTxnNums)) {
                                for (BProdAuthCtrl bMchntAuthCtrl : selectedTxnNums) {
                                    //对基础产品的费率改成标准产品并脱管
                                    bMchntAuthCtrl.setInstId(entity.getInstId());
//                                    bProdAuthCtrlService.detach(bMchntAuthCtrl);
                                    bMchntAuthCtrl.setProdType(ProdTypeEnum.PROD.getType());
                                    bMchntAuthCtrl.setProdCode(entity.getProdCode());

                                    if (pTxnGroup.getTxnGroup().equals(bMchntAuthCtrl.getTxnGroup())) {//如果当前记录的交易大类查出有值  则 对需要展示的交易大类 复选框勾上
                                        pTxnGroup.setIsChecked(BusinessContainer.YES);
                                    }
                                    for (PTxnAuthMap pTxnAuthMap : pTxnAuthMaps) {
                                        if (pTxnAuthMap.getTxnNum().equals(bMchntAuthCtrl.getTxnNum()) && pTxnAuthMap.getBizType().equals(bMchntAuthCtrl.getBizType())) {//如果此处的交易查出有值 则 对需要展示的交易 复选框勾上
                                            pTxnAuthMap.setIsChecked(BusinessContainer.YES);
                                            if (!BusinessContainer.YES.equals(pTxnGroup.getIsChecked())) {//如果交易被选中时，将交易大类选中
                                                pTxnGroup.setIsChecked(BusinessContainer.YES);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }

                    List<BProdStageInfo> stageInfos = bProdStageInfoService.getBaseProdStageList(entity.getInstId(), ProdTypeEnum.BASE_PROD.getType(), entity.getBaseProdCode());

                    if (CollectionUtils.isNotEmpty(stageInfos)) {
                        for (BProdStageInfo stage : stageInfos) {
                            //对基础产品的费率改成标准产品并脱管
                            stage.setInstId(entity.getInstId());
//                            bProdStageInfoService.detach(stage);
                            stage.setProdType(ProdTypeEnum.PROD.getType());
                            stage.setProdCode(entity.getProdCode());
                        }
                    }

//                    if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())
//                            || PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
//                        //此时默认保存基础产品的费率、分期、权限
//                        bProdInfoService.saveProdAndFollowersData(bProdInfoService.getOprMenuId(), bProdInfoService.getOprMenuName(), entity, user, org, feeInfos, stageInfos,
//                                selectedTxnNums, authPrivilegeCheckService, request, bProdInfoService.getWebNextUrl());
//                        BeanUtils.copyProperties(entity, bProdInfo);
//                        bProdInfo.setId(entity.getId());
//                    }

                    result.put("pTxnGroups", txnGroups);
                    result.put("feeInfos", feeInfos);
                    result.put("stageInfos", stageInfos);
                    result.put("entity", bProdInfo);
                } else {//如果查到bProdInfo ，则加载现有的bProdInfo信息
                    bProdInfo.setOptFlag(entity.getOptFlag());

                    if (!PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag())) {
                        //基础产品费率
                        List<BProdFeeInfo> feeInfos = bProdFeeInfoService.getBaseProdFeeList(entity.getInstId(), ProdTypeEnum.BASE_PROD.getType(), entity.getBaseProdCode());
                        //标准产品费率
                        List<BProdFeeInfo> bFeeInfos = bProdFeeInfoService.getProdFeeListAdd(entity.getInstId(), ProdTypeEnum.PROD.getType(), entity.getBaseProdCode(), entity.getProdCode());
                        if (CollectionUtils.isNotEmpty(feeInfos) && CollectionUtils.isNotEmpty(bFeeInfos)) {
                            for (BProdFeeInfo fee : feeInfos) {
                                //对基础产品的费率改成标准产品并脱管
                                fee.setInstId(entity.getInstId());
//                                bProdFeeInfoService.detach(fee);
                                for (BProdFeeInfo bFee : bFeeInfos) {
                                    if (fee.getFeeType().equals(bFee.getFeeType())) {
                                        BeanUtils.copyProperties(bFee, fee);
                                        break;
                                    }
                                }
                            }
                        }
                        //基础产品交易大类、交易(全量交易)
                        List<PTxnGroup> txnGroups = this.findPTxnGroupByList(entity.getInstId(), ProdTypeEnum.BASE_PROD.getType(), entity.getBaseProdCode());
                        //标准产品选中的交易权限
                        List<BProdAuthCtrl> selectedTxnNums = bProdAuthCtrlService.getProdAuthCtrlAdd(entity.getInstId(), ProdTypeEnum.PROD.getType(), entity.getBaseProdCode(), entity.getProdCode());

                        if (CollectionUtils.isNotEmpty(txnGroups)) {
                            Map<String, String> map = upmpSysParamService.findMapDataByPrimaryKey(BusinessContainer.SYS_TXN_GROUP_PARAM, entity.getInstId(), null);
                            getTxnGroup(txnGroups, selectedTxnNums, map);
                        }

                        List<BProdStageInfo> stageInfos = bProdStageInfoService.getProdStageListAdd(entity.getInstId(), ProdTypeEnum.PROD.getType(), entity.getBaseProdCode(), entity.getProdCode());

                        result.put("pTxnGroups", txnGroups);
                        result.put("feeInfos", feeInfos);
                        result.put("stageInfos", stageInfos);
                        result.put("entity", bProdInfo);
                    }
                }
            }
        } else {//审核 现在只有add cancel审批
            BProdInfo bProdInfo = bizTmpService.getObjFromBizTmp(entity.getId(), BProdInfo.class);
            bProdInfo.setOptFlag(entity.getOptFlag());

            //基础产品费率
            List<BProdFeeInfo> feeInfos = bProdFeeInfoService.getProdFeeListAdd(entity.getInstId(), ProdTypeEnum.PROD.getType(), entity.getBaseProdCode(), entity.getProdCode());

            //基础产品交易大类、交易(全量交易)
            List<PTxnGroup> txnGroups = pTxnCfgService.findPTxnGroupByList("", entity.getBaseProdCode());
            //标准产品选中的交易权限
            List<BProdAuthCtrl> selectedTxnNums = bProdAuthCtrlService.getProdAuthCtrlAdd(entity.getInstId(), ProdTypeEnum.PROD.getType(), entity.getBaseProdCode(), entity.getProdCode());

            if (CollectionUtils.isNotEmpty(txnGroups)) {
                Map<String, String> map = upmpSysParamService.findMapDataByPrimaryKey(BusinessContainer.SYS_TXN_GROUP_PARAM, entity.getInstId(), null);
                getTxnGroup(txnGroups, selectedTxnNums, map);
            }

            List<BProdStageInfo> stageInfos = bProdStageInfoService.getProdStageListAdd(entity.getInstId(), ProdTypeEnum.PROD.getType(), entity.getBaseProdCode(), entity.getProdCode());

            result.put("pTxnGroups", txnGroups);
            result.put("feeInfos", feeInfos);
            result.put("stageInfos", stageInfos);
            result.put("entity", bProdInfo);
        }
        return result;
    }

    //首页停用 启用标准产品
    @Transactional(value = "transactionManager")
    @Override
    public void changeStatus(BProdInfo bProdInfo) {
        // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String lastUpddt = DateUtil.getDateFormat(new Date(), DateUtil.FULL_TIME_WITH_MILL_SPLIT_PATTERN);
        //标准产品
        List<BProdInfo> prodList = this.findProdByCode(bProdInfo.getInstId(), bProdInfo.getProdCode());
        for (BProdInfo prod : prodList) {
            if (PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(bProdInfo.getOptFlag())) {
                prod.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_STOP_PASS.getType());
                prod.setProdStatus(BizDataStatusEnum.STATUS_STOPED.getType());
            }
            if (PageOptFlagEnum.OPT_FLAG_USE.getType().equals(bProdInfo.getOptFlag())) {
                prod.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_USE_PASS.getType());
                prod.setProdStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
            }
            prod.setLastOprId(user.getId());
            prod.setLastUpdateTime(lastUpddt);
        }
        this.updateBatchById(prodList);

        LambdaQueryWrapper<BProdFeeInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BProdFeeInfo::getInstId, user.getInstId());
        wrapper.eq(BProdFeeInfo::getProdCode, bProdInfo.getProdCode());
        List<BProdFeeInfo> feeList = bProdFeeInfoService.list(wrapper);
        for (BProdFeeInfo prodFee : feeList) {
            if (PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(bProdInfo.getOptFlag())) {
                prodFee.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_STOP_PASS.getType());
                prodFee.setFeeStatus(BizDataStatusEnum.STATUS_STOPED.getType());
            }
            if (PageOptFlagEnum.OPT_FLAG_USE.getType().equals(bProdInfo.getOptFlag())) {
                prodFee.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_USE_PASS.getType());
                prodFee.setFeeStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
            }
            prodFee.setLastOprId(user.getId());
            prodFee.setLastUpdateTime(lastUpddt);
        }
        this.bProdFeeInfoService.updateBatchById(feeList);
        LambdaQueryWrapper<BProdStageInfo> bProdStageInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        bProdStageInfoLambdaQueryWrapper.eq(BProdStageInfo::getInstId, user.getInstId());
        bProdStageInfoLambdaQueryWrapper.eq(BProdStageInfo::getProdCode, bProdInfo.getProdCode());
        List<BProdStageInfo> bProdStageList = bProdStageInfoService.list(bProdStageInfoLambdaQueryWrapper);
        for (BProdStageInfo prodStage : bProdStageList) {
            if (PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(bProdInfo.getOptFlag())) {
                prodStage.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_STOP_PASS.getType());
                prodStage.setStageStatus(BizDataStatusEnum.STATUS_STOPED.getType());
            }
            if (PageOptFlagEnum.OPT_FLAG_USE.getType().equals(bProdInfo.getOptFlag())) {
                prodStage.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_USE_PASS.getType());
                prodStage.setStageStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
            }
            prodStage.setLastOprId(user.getId());
            prodStage.setLastUpdateTime(lastUpddt);
        }
        this.bProdStageInfoService.updateBatchById(bProdStageList);

        LambdaQueryWrapper<BProdAuthCtrl> bProdAuthCtrlLambdaQueryWrapper = new LambdaQueryWrapper<>();
        bProdAuthCtrlLambdaQueryWrapper.eq(BProdAuthCtrl::getInstId, user.getInstId());
        bProdAuthCtrlLambdaQueryWrapper.eq(BProdAuthCtrl::getProdCode, bProdInfo.getProdCode());

        List<BProdAuthCtrl> bProdAuthCtrlList = bProdAuthCtrlService.list(bProdAuthCtrlLambdaQueryWrapper);
        for (BProdAuthCtrl prodAuthCtrl : bProdAuthCtrlList) {
            if (PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(bProdInfo.getOptFlag())) {
                prodAuthCtrl.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_STOP_PASS.getType());
                prodAuthCtrl.setStatus(BizDataStatusEnum.STATUS_STOPED.getType());
            }
            if (PageOptFlagEnum.OPT_FLAG_USE.getType().equals(bProdInfo.getOptFlag())) {
                prodAuthCtrl.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_USE_PASS.getType());
                prodAuthCtrl.setStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
            }
            prodAuthCtrl.setLastOprId(user.getId());
            prodAuthCtrl.setLastUpdateTime(lastUpddt);
        }
        this.bProdAuthCtrlService.updateBatchById(bProdAuthCtrlList);
    }

    /**
     * 根据基础产品查询交易分组，每个交易分组下包含哪些交易
     *
     * @param instId
     * @param prodType
     * @param bizProdCode
     * @return
     * @throws RedpException
     */
    public List<PTxnGroup> findPTxnGroupByList(String instId, String prodType, String bizProdCode) throws RedpException {
        QueryWrapper<BProdAuthCtrl> wrapper = new QueryWrapper<>();
        List<PTxnGroup> pTxnCfgList;
        wrapper.select("DISTINCT txn_group as \"txnGroup\"", "base_prod_code  as \"prodCode\" ");
        if (!Common.isBlank(instId)) {
            wrapper.lambda().eq(BProdAuthCtrl::getInstId, instId);
        }
        if (!Common.isBlank(prodType)) {
            wrapper.lambda().eq(BProdAuthCtrl::getProdType, prodType);
        }
        if (!Common.isBlank(bizProdCode)) {
            wrapper.lambda().eq(BProdAuthCtrl::getBaseProdCode, bizProdCode);
        }
        wrapper.lambda().eq(BProdAuthCtrl::getStatus, "01");
        List<Map<String, Object>> list = bProdAuthCtrlService.listMaps(wrapper);
        if (null != list && list.size() > 0) {
            pTxnCfgList = CommonUtils.parseListmapToBean(list, PTxnGroup.class);
            for (PTxnGroup pTxnGroup : pTxnCfgList) {
                pTxnGroup.setpTxnAuthMaps(findPTxnNumByList(instId, prodType, pTxnGroup.getTxnGroup(), pTxnGroup.getProdCode()));
            }
            return pTxnCfgList;
        }
        return null;
    }

    /**
     * 根据交易分组、交易码查询交易码
     *
     * @param instId
     * @param prodType
     * @param txnGroup
     * @param bizProdCode
     * @return
     * @throws
     */
    public List<PTxnAuthMap> findPTxnNumByList(String instId, String prodType, String txnGroup, String bizProdCode) {
        QueryWrapper<BProdAuthCtrl> wrapper = new QueryWrapper<>();
        List<PTxnAuthMap> pTxnCfgList;
        wrapper.select("DISTINCT txn_num as \"txnNum\"", "biz_type  as \"bizType\""
                , "txn_group as \"txnGroup\"", "base_prod_code as \"prodCode\"", "txn_name as \"txnName\"");
        if (!Common.isBlank(instId)) {
            wrapper.lambda().eq(BProdAuthCtrl::getInstId, instId);
        }
        if (!Common.isBlank(prodType)) {
            wrapper.lambda().eq(BProdAuthCtrl::getProdType, prodType);
        }
        if (!Common.isBlank(bizProdCode)) {
            wrapper.lambda().eq(BProdAuthCtrl::getBaseProdCode, bizProdCode);
        }
        if (!Common.isBlank(txnGroup)) {
            wrapper.lambda().eq(BProdAuthCtrl::getTxnGroup, txnGroup);
        }
        wrapper.lambda().eq(BProdAuthCtrl::getStatus, "01");
        List<Map<String, Object>> list = bProdAuthCtrlService.listMaps(wrapper);
        if (null != list && list.size() > 0) {
            pTxnCfgList = CommonUtils.parseListmapToBean(list, PTxnAuthMap.class);
            return pTxnCfgList;
        }
        return null;

    }

    /**
     * 组装交易大类及交易大类下的交易数据
     *
     * @param txnGroup
     * @param selectedTxnNum
     * @param map
     */
    private void getTxnGroup(List<PTxnGroup> txnGroup, List<BProdAuthCtrl> selectedTxnNum, Map<String, String> map) {
        if (CollectionUtils.isNotEmpty(txnGroup)) {
            for (PTxnGroup pTxnGroup : txnGroup) {
                pTxnGroup.setTxnGroupName(map.get(pTxnGroup.getTxnGroup()));
                //获取当前交易大类下的所有交易小类
                List<PTxnAuthMap> pTxnAuthMaps = pTxnGroup.getpTxnAuthMaps();
                if (Common.isNotBlank(selectedTxnNum)) {
                    for (BProdAuthCtrl bMchntAuthCtrl : selectedTxnNum) {
                        if (pTxnGroup.getTxnGroup().equals(bMchntAuthCtrl.getTxnGroup())) {//如果当前记录的交易大类查出有值  则 对需要展示的交易大类 复选框勾上
                            pTxnGroup.setIsChecked(BusinessContainer.YES);
                        }
                        for (PTxnAuthMap pTxnAuthMap : pTxnAuthMaps) {
                            if (pTxnAuthMap.getTxnNum().equals(bMchntAuthCtrl.getTxnNum()) && pTxnAuthMap.getBizType().equals(bMchntAuthCtrl.getBizType())) {//如果此处的交易查出有值 则 对需要展示的交易 复选框勾上
                                pTxnAuthMap.setIsChecked(BusinessContainer.YES);
                                if (!BusinessContainer.YES.equals(pTxnGroup.getIsChecked())) {//如果交易被选中时，将交易大类选中
                                    pTxnGroup.setIsChecked(BusinessContainer.YES);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public void saveFromSubListPageData(List<BProdInfo> datas, String optFlag) throws RedpException {
//        UpmpSysParam defaultInst = upmpSysParamService.getById(UpmpConstant.DEAFULT_INST_PARAM_ID);
//        UpmpUserInfoVO user = RedpUpmpUtil.getCurrentUser(defaultInst.getPrimaryValue());
        // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (Common.isBlank(datas.get(0).getInstId())) {
            if (Common.isNotBlank(user) && Common.isNotBlank(user.getInstId())) {
                datas.get(0).setInstId(user.getInstId());
            }
        }
        if (Common.isNotBlank(user) && Common.isNotBlank(user.getInstId())
                && !user.isAdmin() && !datas.get(0).getInstId().equals(user.getInstId())) {
            log.error("请求参数与用户身份不符");
            throw new RedpException("请求参数与用户身份不符");
        }
//        user.setInstId("000");
//        user.setId("1");
        String lastUpddt = DateUtil.getDateFormat(new Date(), DateUtil.FULL_TIME_WITH_MILL_SPLIT_PATTERN);
        String instId = "";
        String prodCode = "";
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            //只取一条标准产品放在tmp中 从表都不往tmp表中放数据
            String tmpId = "";
            BProdInfo bProdInfoTmp = new BProdInfo();
            List<BProdInfo> listUpd = new ArrayList<BProdInfo>();//待更新的数据 从基础产品配置中保存了数据   然后在标准产品页面勾选
            List<BProdInfo> listDel = new ArrayList<BProdInfo>();//待删除的数据 从基础产品配置中保存了数据   但是没有在产品页面勾选
            List<BProdInfo> listNew = new ArrayList<BProdInfo>();//待新增的数据 没有在基础产品配置中保存数据 但是在标准产品页面勾选
            UpmpPrivilegeCheck privilegeCheck = new UpmpPrivilegeCheck();
            if (CollectionUtils.isNotEmpty(datas)) {
                //标准产品保存的所有基础产品代码
                StringBuffer baseProdBuffer = new StringBuffer();
                instId = datas.get(0).getInstId();
                prodCode = datas.get(0).getProdCode();
                //从基础产品配置中保存了数据
//                List<BProdInfo> dbProdList=this.findProdByCode(instId,prodCode);
                String status = BizDataStatusEnum.STATUS_NORMAL.getType();
                String auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType();
                privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(user.getInstId(),
                        oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_ADD.getType());
                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    status = BizDataStatusEnum.STATUS_DRAFT.getType();
                    auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_ADD_CHECKING.getType();
                }
                for (BProdInfo bProdInfo : datas) {
                    baseProdBuffer.append(bProdInfo.getBaseProdCode());
                    BProdInfo bProdInfoDB = this.findProdByUK(bProdInfo.getInstId(), bProdInfo.getProdCode(), bProdInfo.getBaseProdCode());
                    if (Common.isBlank(bProdInfoDB)) {
                        BBaseProdInfo bBaseProdInfo = bBaseProdInfoService.findByUK(bProdInfo.getInstId(), bProdInfo.getBaseProdCode());
                        bProdInfo.setAlipayChannelId(bBaseProdInfo.getAlipayChannelId());
                        bProdInfo.setWechatChannelId(bBaseProdInfo.getWechatChannelId());
                        bProdInfo.setProdStatus(status);
                        bProdInfo.setAuditStatus(auditStatus);
                        bProdInfo.setCreateTime(lastUpddt);
                        bProdInfo.setLastOprId(user.getId());
                        bProdInfo.setLastUpdateTime(lastUpddt);
                        bProdInfo.setOprId(user.getId());
                        listNew.add(bProdInfo);
                    } else {
                        //目前界面只能修改微信、支付宝通道类型
                        bProdInfoDB.setWechatChannelId(bProdInfo.getWechatChannelId());
                        bProdInfoDB.setAlipayChannelId(bProdInfo.getAlipayChannelId());
                        bProdInfoDB.setProdName(bProdInfo.getProdName());
                        bProdInfoDB.setProdDesc(bProdInfo.getProdDesc());
                        bProdInfoDB.setProdStatus(status);
                        bProdInfoDB.setAuditStatus(auditStatus);
                        bProdInfoDB.setLastOprId(user.getId());
                        bProdInfoDB.setLastUpdateTime(lastUpddt);
                        BeanUtils.copyProperties(bProdInfoDB, bProdInfo);
                        listUpd.add(bProdInfo);
                    }
                }
                String baseProdStr = baseProdBuffer.toString();
               /* for(BProdInfo dbProdInfo:dbProdList){
                    if(baseProdStr.indexOf(dbProdInfo.getBaseProdCode())<0){
                        listDel.add(dbProdInfo);
                    }
                }*/
            }

            if (CollectionUtils.isNotEmpty(listUpd)) {//修改
                //将基础产品配置中保存数据的状态更新成 草稿 新增审核中
                //保存主表
                this.saveOrUpdateBatch(listUpd);
                for (BProdInfo modProdInfo : listUpd) {
                    if (!BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(modProdInfo.getBaseProdCode())) {
//                        List<BProdFeeInfo> bProdFeeList = bProdFeeInfoDao.getProdFeeListAdd(modProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), modProdInfo.getBaseProdCode(), modProdInfo.getProdCode());
                        for (BProdFeeInfo bProdFeeInfo : modProdInfo.getBProdFeeList()) {
                            bProdFeeInfo.setFeeStatus(modProdInfo.getProdStatus());
                            bProdFeeInfo.setAuditStatus(modProdInfo.getAuditStatus());
                            bProdFeeInfo.setLastOprId(user.getId());
                            bProdFeeInfo.setLastUpdateTime(lastUpddt);
                        }
                        bProdFeeInfoService.saveOrUpdateBatch(modProdInfo.getBProdFeeList());
                    }
                    if (BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(modProdInfo.getBaseProdCode())) {
                        //信用卡分期产品
//                        List<BProdStageInfo> bProdStageList = bProdStageInfoDao.getProdStageListAdd(modProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), modProdInfo.getBaseProdCode(), modProdInfo.getProdCode());
                        for (BProdStageInfo bProdStageInfo : modProdInfo.getBProdStageList()) {
                            bProdStageInfo.setStageStatus(modProdInfo.getProdStatus());
                            bProdStageInfo.setAuditStatus(modProdInfo.getAuditStatus());
                            bProdStageInfo.setLastOprId(user.getId());
                            bProdStageInfo.setLastUpdateTime(lastUpddt);
                        }
                        bProdStageInfoService.saveOrUpdateBatch(modProdInfo.getBProdStageList());
                    }
//                    List<BProdAuthCtrl> bProdAuthCtrlList = bProdAuthCtrlDao.getProdAuthCtrlAdd(modProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), modProdInfo.getBaseProdCode(), modProdInfo.getProdCode());
                    for (BProdAuthCtrl bProdAuthCtrl : modProdInfo.getBProdAuthCtrlList()) {
                        bProdAuthCtrl.setStatus(modProdInfo.getProdStatus());
                        bProdAuthCtrl.setAuditStatus(modProdInfo.getAuditStatus());
                        bProdAuthCtrl.setLastOprId(user.getId());
                        bProdAuthCtrl.setLastUpdateTime(lastUpddt);
                    }
                    bProdAuthCtrlService.saveOrUpdateBatch(modProdInfo.getBProdAuthCtrlList());
                }

                bProdInfoTmp = listUpd.get(0);
                tmpId = listUpd.get(0).getId();
            }
            if (CollectionUtils.isNotEmpty(listNew)) {//新增
                //保存主表
                this.saveOrUpdateBatch(listNew);
                //初始化从表数据
                for (BProdInfo newProdInfo : listNew) {
                    String now = DateUtils.formatDate(new Date(), DateUtils.FORMAT_YYYYMMDD);
                    if (!BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(newProdInfo.getBaseProdCode())) {
                        //除了信用卡分期其他都单独设置费率
                        //先检查产品费率表中是否有标准产品的费率
//                        List<BProdFeeInfo> bProdFeeList = bProdFeeInfoDao.getProdFeeListAdd(newProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), newProdInfo.getBaseProdCode(), newProdInfo.getProdCode());
                        if (CollectionUtils.isEmpty(newProdInfo.getBProdFeeList())) {
                            List<BProdFeeInfo> bProdFeeList = bProdFeeInfoService.getBaseProdFeeList(newProdInfo.getInstId(), ProdTypeEnum.BASE_PROD.getType(), newProdInfo.getBaseProdCode());
                            for (BProdFeeInfo bProdFeeInfo : bProdFeeList) {
                                BProdFeeInfo bProdFeeInfoDb = new BProdFeeInfo();
                                bProdFeeInfo.setProdType(ProdTypeEnum.PROD.getType());
                                bProdFeeInfo.setProdCode(newProdInfo.getProdCode());
                                bProdFeeInfo.setFeeEffectiveDate(now);
                                bProdFeeInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                                bProdFeeInfo.setFeeStatus(newProdInfo.getProdStatus());
                                bProdFeeInfo.setAuditStatus(newProdInfo.getAuditStatus());
                                bProdFeeInfo.setOprId(user.getId());
                                bProdFeeInfo.setCreateTime(lastUpddt);
                                bProdFeeInfo.setLastOprId(user.getId());
                                bProdFeeInfo.setLastUpdateTime(lastUpddt);
                                bProdFeeInfoService.convertFeeAmt(bProdFeeInfo, bProdFeeInfo);
//                                bProdFeeInfoService.detach(bProdFeeInfo);
                                BeanUtils.copyProperties(bProdFeeInfo, bProdFeeInfoDb);
                                bProdFeeInfoDb.setId(null);
                                bProdFeeInfoService.save(bProdFeeInfoDb);
                            }
                        } else {
                            for (BProdFeeInfo bProdFeeInfo : newProdInfo.getBProdFeeList()) {
                                BProdFeeInfo bProdFeeInfoDb = new BProdFeeInfo();
                                bProdFeeInfo.setProdType(ProdTypeEnum.PROD.getType());
                                bProdFeeInfo.setProdCode(newProdInfo.getProdCode());
                                bProdFeeInfo.setFeeEffectiveDate(now);
                                bProdFeeInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                                bProdFeeInfo.setFeeStatus(newProdInfo.getProdStatus());
                                bProdFeeInfo.setAuditStatus(newProdInfo.getAuditStatus());
                                bProdFeeInfo.setOprId(user.getId());
                                bProdFeeInfo.setCreateTime(lastUpddt);
                                bProdFeeInfo.setLastOprId(user.getId());
                                bProdFeeInfo.setLastUpdateTime(lastUpddt);
                                bProdFeeInfoService.convertFeeAmt(bProdFeeInfo, bProdFeeInfo);
//                                bProdFeeInfoService.detach(bProdFeeInfo);
                                BeanUtils.copyProperties(bProdFeeInfo, bProdFeeInfoDb);
                                bProdFeeInfoService.save(bProdFeeInfoDb);
                            }
                        }
                    }
                    if (BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(newProdInfo.getBaseProdCode())) {
                        //信用卡分期产品
                      /*  List<BProdStageInfo> bProdStageList = bProdStageInfoDao.getProdStageListAdd(newProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), newProdInfo.getBaseProdCode(), newProdInfo.getProdCode());
                        if (CollectionUtils.isNotEmpty(bProdStageList)){
                            //此情况可能为进入了基础产品配置页面 增加了分期产品信息但是没有保存基础产品信息 所以导致数据库中没有基础产品信息反而有分期产品信息
                            bProdStageInfoService.delete(bProdStageList);
                        }*/
                        if (CollectionUtils.isEmpty(newProdInfo.getBProdStageList())) {
                            //新增、修改时如果界面勾选了基础产品但是没有点击选择并配置，或者点击选中并配置，但是在配置界面不一定点了保存，这时需取基础产品的费率
                            List<BProdStageInfo> bProdStageList = bProdStageInfoService.getBaseProdStageList(newProdInfo.getInstId(), ProdTypeEnum.BASE_PROD.getType(), newProdInfo.getBaseProdCode());

                            for (BProdStageInfo bProdStageInfo : bProdStageList) {
                                BProdStageInfo bProdStageInfoDb = new BProdStageInfo();
                                bProdStageInfo.setProdType(ProdTypeEnum.PROD.getType());
                                bProdStageInfo.setFeeEffectiveDate(now);
                                bProdStageInfo.setProdCode(newProdInfo.getProdCode());
                                bProdStageInfo.setStagePrimaryKey(bProdStageInfo.getProdType()
                                        + String.format("%2s", newProdInfo.getProdCode()) + bProdStageInfo.getBaseProdCode()
                                        + String.format("%32s", bProdStageInfo.getProdStageCode())
                                        + String.format("%2s", bProdStageInfo.getProdStageNum()) + bProdStageInfo.getFeeEffectiveDate());
                                bProdStageInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                                bProdStageInfo.setStageStatus(newProdInfo.getProdStatus());
                                bProdStageInfo.setAuditStatus(newProdInfo.getAuditStatus());
                                bProdStageInfo.setCreateTime(lastUpddt);
                                bProdStageInfo.setLastOprId(user.getId());
                                bProdStageInfo.setLastUpdateTime(lastUpddt);
                                bProdStageInfo.setOprId(user.getId());
//                                bProdStageInfoService.detach(bProdStageInfo);
                                BeanUtils.copyProperties(bProdStageInfo, bProdStageInfoDb);
                                bProdStageInfoDb.setId(null);
                                bProdStageInfoService.save(bProdStageInfoDb);
                            }
                        } else {
                            for (BProdStageInfo bProdStageInfo : newProdInfo.getBProdStageList()) {
                                BProdStageInfo bProdStageInfoDb = new BProdStageInfo();
                                bProdStageInfo.setProdType(ProdTypeEnum.PROD.getType());
                                bProdStageInfo.setFeeEffectiveDate(now);
                                bProdStageInfo.setProdCode(newProdInfo.getProdCode());
                                bProdStageInfo.setStagePrimaryKey(bProdStageInfo.getProdType()
                                        + String.format("%2s", newProdInfo.getProdCode()) + bProdStageInfo.getBaseProdCode()
                                        + String.format("%32s", bProdStageInfo.getProdStageCode())
                                        + String.format("%2s", bProdStageInfo.getProdStageNum()) + bProdStageInfo.getFeeEffectiveDate());
                                bProdStageInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                                bProdStageInfo.setStageStatus(newProdInfo.getProdStatus());
                                bProdStageInfo.setAuditStatus(newProdInfo.getAuditStatus());
                                bProdStageInfo.setCreateTime(lastUpddt);
                                bProdStageInfo.setLastOprId(user.getId());
                                bProdStageInfo.setLastUpdateTime(lastUpddt);
                                bProdStageInfo.setOprId(user.getId());
                                BeanUtils.copyProperties(bProdStageInfo, bProdStageInfoDb);
                                bProdStageInfoService.save(bProdStageInfoDb);
                            }
                        }
                    }
//                    List<BProdAuthCtrl> bProdAuthCtrlList = bProdAuthCtrlService.getProdAuthCtrlAdd(newProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), newProdInfo.getBaseProdCode(), newProdInfo.getProdCode());
                    if (CollectionUtils.isEmpty(newProdInfo.getBProdAuthCtrlList())) {
                        //新增、修改时如果界面勾选了基础产品但是没有点击选择并配置，或者点击选中并配置，但是在配置界面不一定点了保存，这时需取基础产品的费率
                        List<BProdAuthCtrl> bProdAuthCtrlList = bProdAuthCtrlService.getBaseProdAuthCtrl(newProdInfo.getInstId(), ProdTypeEnum.BASE_PROD.getType(), newProdInfo.getBaseProdCode());
                        for (BProdAuthCtrl bProdAuthCtrl : bProdAuthCtrlList) {
                            BProdAuthCtrl bProdAuthCtrlDb = new BProdAuthCtrl();
                            bProdAuthCtrl.setProdType(ProdTypeEnum.PROD.getType());
                            bProdAuthCtrl.setProdCode(newProdInfo.getProdCode());
                            bProdAuthCtrl.setStatus(newProdInfo.getProdStatus());
                            bProdAuthCtrl.setAuditStatus(newProdInfo.getAuditStatus());
                            bProdAuthCtrl.setCreateTime(lastUpddt);
                            bProdAuthCtrl.setLastOprId(user.getId());
                            bProdAuthCtrl.setLastUpdateTime(lastUpddt);
                            bProdAuthCtrl.setOprId(user.getId());
//                            bProdAuthCtrlService.detach(bProdAuthCtrl);
                            BeanUtils.copyProperties(bProdAuthCtrl, bProdAuthCtrlDb);
                            bProdAuthCtrlDb.setId(null);
                            bProdAuthCtrlService.save(bProdAuthCtrlDb);
                        }
                    } else {
                        for (BProdAuthCtrl bProdAuthCtrl : newProdInfo.getBProdAuthCtrlList()) {
                            BProdAuthCtrl bProdAuthCtrlDb = new BProdAuthCtrl();
                            bProdAuthCtrl.setProdType(ProdTypeEnum.PROD.getType());
                            bProdAuthCtrl.setProdCode(newProdInfo.getProdCode());
                            bProdAuthCtrl.setStatus(newProdInfo.getProdStatus());
                            bProdAuthCtrl.setAuditStatus(newProdInfo.getAuditStatus());
                            bProdAuthCtrl.setCreateTime(lastUpddt);
                            bProdAuthCtrl.setLastOprId(user.getId());
                            bProdAuthCtrl.setLastUpdateTime(lastUpddt);
                            bProdAuthCtrl.setOprId(user.getId());
                            BeanUtils.copyProperties(bProdAuthCtrl, bProdAuthCtrlDb);
                            bProdAuthCtrlService.save(bProdAuthCtrlDb);
                        }
                    }

                    if (StringUtils.isEmpty(tmpId)) {
                        bProdInfoTmp = listNew.get(0);
                        tmpId = listNew.get(0).getId();
                    }
                }
            }
     /*       if (CollectionUtils.isNotEmpty(listDel)) {//删除
                this.delete(listDel);
                //删除从表数据
                for(BProdInfo newProdInfo:listDel){
                    String now = DateUtils.formatDate(new Date(), DateUtils.FORMAT_YYYYMMDD);
                    if (!BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(newProdInfo.getBaseProdCode())) {
                        List<BProdFeeInfo> bProdFeeList = bProdFeeInfoDao.getProdFeeListAdd(newProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), newProdInfo.getBaseProdCode(), newProdInfo.getProdCode());
                        bProdFeeInfoService.delete(bProdFeeList);
                    }
                    if (BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(newProdInfo.getBaseProdCode())) {
                        //信用卡分期产品
                        List<BProdStageInfo> bProdStageList = bProdStageInfoDao.getProdStageListAdd(newProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), newProdInfo.getBaseProdCode(), newProdInfo.getProdCode());
                        bProdStageInfoService.delete(bProdStageList);
                    }
                    List<BProdAuthCtrl> bProdAuthCtrlList = bProdAuthCtrlService.getProdAuthCtrlAdd(newProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), newProdInfo.getBaseProdCode(), newProdInfo.getProdCode());
                    bProdAuthCtrlService.delete(bProdAuthCtrlList);
                }
            }*/

            if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked()) && StringUtils.isNotEmpty(tmpId)) {
                bizTmpService.saveBizTmp(bProdInfoTmp, user, user.getInstId(), BizOprEnum.OPR_ADD.getType(), DateUtil.getDateFormat(new Date(), DateUtil.FULL_TIME_WITH_MILL_SPLIT_PATTERN)
                        , oprMenuId, oprMenuName, bProdInfoTmp.getProdStatus(), bProdInfoTmp.getAuditStatus(), String.valueOf(bProdInfoTmp.getId()), webNextUrl, null, null, null);
            }
        } else if (PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(optFlag)) {
            //只取一条标准产品放在tmp中 从表都不往tmp表中放数据
            BProdInfo bProdInfoTmp = new BProdInfo();
            UpmpPrivilegeCheck privilegeCheck = new UpmpPrivilegeCheck();
            instId = datas.get(0).getInstId();
            prodCode = datas.get(0).getProdCode();
            List<BProdInfo> dbProdList = this.findProdByCode(instId, prodCode);
            if (CollectionUtils.isNotEmpty(dbProdList)) {
                String status = BizDataStatusEnum.STATUS_CANCELED.getType();
                String auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_PASS.getType();
                privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(user.getInstId(),
                        oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_CANCEL.getDesc());
                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    status = BizDataStatusEnum.STATUS_NORMAL.getType();
                    auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType();
                } else {
                    status = BizDataStatusEnum.STATUS_CANCELED.getType();
                    auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_PASS.getType();
                }
                for (BProdInfo bProdInfo : dbProdList) {
                    bProdInfo.setProdStatus(status);
                    bProdInfo.setAuditStatus(auditStatus);
                    bProdInfo.setLastOprId(user.getId());
                    bProdInfo.setLastUpdateTime(lastUpddt);
                }
                this.saveOrUpdateBatch(dbProdList);
                bProdInfoTmp = dbProdList.get(0);
                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked()) && StringUtils.isNotEmpty(bProdInfoTmp.getId())) {
                    bizTmpService.saveBizTmp(bProdInfoTmp, user, user.getInstId(), BizOprEnum.OPR_CANCEL.getType(), DateUtil.getDateFormat(new Date(), DateUtil.FULL_TIME_WITH_MILL_SPLIT_PATTERN)
                            , oprMenuId, oprMenuName, bProdInfoTmp.getProdStatus(), bProdInfoTmp.getAuditStatus(), String.valueOf(bProdInfoTmp.getId()), webNextUrl, null, null, null);
                }
            }
        } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)) {
            instId = datas.get(0).getInstId();
            prodCode = datas.get(0).getProdCode();
            String opt = datas.get(0).getOpt();
            String auditRefuseReason = datas.get(0).getAuditRefuseReason();
            List<BProdInfo> dbProdList = this.findProdByCode(instId, prodCode);
            for (BProdInfo bProdInfo : dbProdList) {
                String status = bProdInfo.getProdStatus();
                String auditStatus = bProdInfo.getAuditStatus();
                if (BizDataAuditStatusEnum.AUDIT_STATUS_ADD_CHECKING.getType().equals(auditStatus)) {
                    if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(opt)) {
                        status = BizDataStatusEnum.STATUS_NORMAL.getType();
                        auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType();
                    } else {
                        auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType();
                    }
                } else if (BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(auditStatus)) {
                    if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(opt)) {
                        status = BizDataStatusEnum.STATUS_CANCELED.getType();
                        auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_PASS.getType();
                    } else {
                        auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_REJECT.getType();
                    }
                }

                bProdInfo.setProdStatus(status);
                bProdInfo.setAuditStatus(auditStatus);
                bProdInfo.setLastOprId(user.getId());
                bProdInfo.setLastUpdateTime(lastUpddt);
                bProdInfo.setLastAuditId(user.getId());
                bProdInfo.setLastAuditTime(lastUpddt);
                bProdInfo.setAuditRefuseReason(auditRefuseReason);
                this.save(bProdInfo);

                if (!BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(bProdInfo.getBaseProdCode())) {
                    List<BProdFeeInfo> bProdFeeList = bProdFeeInfoService.getProdFeeListAdd(bProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), bProdInfo.getBaseProdCode(), bProdInfo.getProdCode());
                    for (BProdFeeInfo bProdFeeInfo : bProdFeeList) {
                        bProdFeeInfo.setFeeStatus(bProdInfo.getProdStatus());
                        bProdFeeInfo.setAuditStatus(bProdInfo.getAuditStatus());
                        bProdFeeInfo.setLastOprId(user.getId());
                        bProdFeeInfo.setLastUpdateTime(lastUpddt);
                        bProdFeeInfo.setLastAuditId(user.getId());
                        bProdFeeInfo.setLastAuditTime(lastUpddt);
                    }
                    bProdFeeInfoService.saveOrUpdateBatch(bProdFeeList);
                }
                if (BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(bProdInfo.getBaseProdCode())) {
                    //信用卡分期产品
                    List<BProdStageInfo> bProdStageList = bProdStageInfoService.getProdStageListAdd(bProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), bProdInfo.getBaseProdCode(), bProdInfo.getProdCode());
                    for (BProdStageInfo bProdStageInfo : bProdStageList) {
                        bProdStageInfo.setStageStatus(bProdInfo.getProdStatus());
                        bProdStageInfo.setAuditStatus(bProdInfo.getAuditStatus());
                        bProdStageInfo.setLastOprId(user.getId());
                        bProdStageInfo.setLastUpdateTime(lastUpddt);
                        bProdStageInfo.setLastAuditId(user.getId());
                        bProdStageInfo.setLastAuditTime(lastUpddt);
                    }
                    bProdStageInfoService.saveOrUpdateBatch(bProdStageList);
                }
                List<BProdAuthCtrl> bProdAuthCtrlList = bProdAuthCtrlService.getProdAuthCtrlAdd(bProdInfo.getInstId(), ProdTypeEnum.PROD.getType(), bProdInfo.getBaseProdCode(), bProdInfo.getProdCode());
                for (BProdAuthCtrl bProdAuthCtrl : bProdAuthCtrlList) {
                    bProdAuthCtrl.setStatus(bProdInfo.getProdStatus());
                    bProdAuthCtrl.setAuditStatus(bProdInfo.getAuditStatus());
                    bProdAuthCtrl.setLastOprId(user.getId());
                    bProdAuthCtrl.setLastUpdateTime(lastUpddt);
                    bProdAuthCtrl.setLastAuditId(user.getId());
                    bProdAuthCtrl.setLastAuditTime(lastUpddt);
                }
                bProdAuthCtrlService.saveOrUpdateBatch(bProdAuthCtrlList);

                BizTmp bizTmp = bizTmpService.getById(bProdInfo.getId());
                if (bizTmp != null) {
                    bizTmpService.delete(bizTmp.getRealId());
                }
            }
        }
    }
    //标准产品-基础产品-配置界面(add 操作时)保存信息 需要审核 代码重构
    @Override
    @Transactional(value = "transactionManager")
    public OperationResult saveProdAndFollowersData(BProdInfo entity, UpmpUserInfoVO user, UpmpOrganization org, String optFlag) {

        Map<String, Object> result = com.google.common.collect.Maps.newHashMap();
        String lastUpddt = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
        //添加一个中间状态 在产品正式提交之后变为草稿状态
        String status="M";
        String auditStatus=BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType();
        //更新t_b_prod_info中所有的prod_name和prod_desc
//        this.updateProdInfo(entity,status);

        BProdInfo bProdInfoDB = this.findProdByUK(entity.getInstId(),entity.getProdCode(),entity.getBaseProdCode());
        //保存主表信息
        if(Common.isBlank(bProdInfoDB)){
            entity.setId(null);
            entity.setProdStatus(status);
            entity.setAuditStatus(auditStatus);
            entity.setCreateTime(lastUpddt);
            entity.setLastOprId(user.getId());
            entity.setLastUpdateTime(lastUpddt);
            entity.setOprId(user.getId());
        }else{
            bProdInfoDB.setProdName(entity.getProdName());
            bProdInfoDB.setProdDesc(entity.getProdDesc());
            bProdInfoDB.setProdStatus(status);
            bProdInfoDB.setWechatChannelId(entity.getWechatChannelId());
            bProdInfoDB.setAlipayChannelId(entity.getAlipayChannelId());
            bProdInfoDB.setAuditStatus(auditStatus);
            bProdInfoDB.setLastOprId(user.getId());
            bProdInfoDB.setLastUpdateTime(lastUpddt);
            bProdInfoDB.setBProdFeeList(entity.getBProdFeeList());
            bProdInfoDB.setBProdAuthCtrlList(entity.getBProdAuthCtrlList());
            bProdInfoDB.setBProdStageList(entity.getBProdStageList());
//            this.detach(bProdInfoDB);
            BeanUtils.copyProperties(bProdInfoDB,entity);
        }
        this.saveOrUpdate(entity);

        //保存从表信息
        String now = DateUtils.formatDate(new Date(),DateUtils.FORMAT_YYYYMMDD);
        if(!BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(entity.getBaseProdCode())) {
            //除了信用卡分期其他都单独设置费率
            List<BProdFeeInfo> listFeeDB= null;
            try {
                listFeeDB = bProdFeeInfoService.getProdFeeListAdd(entity.getInstId(), ProdTypeEnum.PROD.getType(), entity.getBaseProdCode(),entity.getProdCode());
            } catch (RedpException e) {
                e.printStackTrace();
            }
            List<BProdFeeInfo> listFeeDBDel= Lists.newArrayList();//待删除的数据
            //查找提交数据中无，数据库有的数据
            for(BProdFeeInfo bProdFeeInfoDB : listFeeDB){
                boolean del=true;
                for (BProdFeeInfo bProdFeeInfo : entity.getBProdFeeList()) {
                    if( ProdTypeEnum.BASE_PROD.getType().equals(bProdFeeInfoDB.getProdType()) ||
                            (bProdFeeInfoDB.getInstId().equals(bProdFeeInfo.getInstId())
                            &&bProdFeeInfoDB.getProdType().equals(bProdFeeInfo.getProdType())
                            &&bProdFeeInfoDB.getBaseProdCode().equals(bProdFeeInfo.getBaseProdCode())
                            &&bProdFeeInfoDB.getProdCode().equals(bProdFeeInfo.getProdCode())
                            &&bProdFeeInfoDB.getFeeType().equals(bProdFeeInfo.getFeeType()))){
                        del=false;
                    }
                }
                if(del){//如果需要删除则从正式表取出待删除
                    listFeeDBDel.add(bProdFeeInfoDB);
                }
            }
            if(listFeeDBDel.size()>0){//从正式表删除
                bProdFeeInfoService.delete(listFeeDBDel);
            }
            for (BProdFeeInfo bProdFeeInfo : entity.getBProdFeeList()) {
                BProdFeeInfo bProdFeeDB =
                        bProdFeeInfoService.getEffectProdFeeAdd(bProdFeeInfo.getInstId(), ProdTypeEnum.PROD.getType(), bProdFeeInfo.getBaseProdCode(), bProdFeeInfo.getProdCode(), bProdFeeInfo.getFeeType(), Integer.valueOf(now));
                if (Common.isBlank(bProdFeeDB)) {//如果数据库中查询不到则初始化
                    bProdFeeInfo.setFeeEffectiveDate(now);
                    bProdFeeInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                    bProdFeeInfo.setFeeStatus(status);
                    bProdFeeInfo.setAuditStatus(auditStatus);
                    bProdFeeInfo.setLastOprId(user.getId());
                    bProdFeeInfo.setLastUpdateTime(lastUpddt);
                    bProdFeeInfo.setCreateTime(lastUpddt);
                    bProdFeeInfo.setOprId(user.getId());
                    bProdFeeInfo.setProdType(ProdTypeEnum.PROD.getType());
                    bProdFeeInfoService.convertFeeAmt(bProdFeeInfo,bProdFeeInfo);
                    bProdFeeInfo.setId(null);
                } else {
                    bProdFeeDB.setFeeInputMode(bProdFeeInfo.getFeeInputMode());
                    bProdFeeDB.setFeeRate(bProdFeeInfo.getFeeRate());
                    bProdFeeInfoService.convertFeeAmt(bProdFeeDB,bProdFeeInfo);
                    BeanUtils.copyProperties(bProdFeeDB,bProdFeeInfo);
                    bProdFeeInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                    bProdFeeInfo.setFeeStatus(status);
                    bProdFeeInfo.setAuditStatus(auditStatus);
                    bProdFeeInfo.setLastOprId(user.getId());
                    bProdFeeInfo.setLastUpdateTime(lastUpddt);
//                    bProdFeeInfoService.detach(bProdFeeDB);
                }
                bProdFeeInfoService.saveOrUpdate(bProdFeeInfo);
            }
        }
        //界面操作时分期有修改按钮、删除按钮，需要判断是否有需要删除的数据
        if(BaseProdCodeEnum.CREDIT_CARD_STAGE_PROD.getType().equals(entity.getBaseProdCode())) {
            List<BProdStageInfo> listDB = bProdStageInfoService.getProdStageListAdd(entity.getInstId(),ProdTypeEnum.PROD.getType(),entity.getBaseProdCode(),entity.getProdCode());
            List<BProdStageInfo> listDBDel= Lists.newArrayList();//待删除的数据，需要审核时只从临时表删除
            //查找提交数据中无，数据库有的数据
            for(BProdStageInfo bProdStageDB : listDB){
                boolean del=true;
                for (BProdStageInfo bProdStageInfo : entity.getBProdStageList()) {
                    if(bProdStageDB.getId().equals(bProdStageInfo.getId())){
                        del=false;
                        break;
                    }
                }
                if(del){//如果需要删除则从正式表表取出待删除
                    listDBDel.add(bProdStageDB);
                }
            }
            if(listDBDel.size()>0){//从正式表删除
                bProdStageInfoService.delete(listDBDel);
            }
            for (BProdStageInfo bProdStageInfo : entity.getBProdStageList()) {
                BProdStageInfo bProdStageDB =
                        bProdStageInfoService.getEffectProdStageAdd(bProdStageInfo.getInstId(),ProdTypeEnum.PROD.getType(), bProdStageInfo.getBaseProdCode(), bProdStageInfo.getProdCode(), bProdStageInfo.getProdStageCode(), bProdStageInfo.getProdStageNum(), Integer.valueOf(now));
                if (Common.isBlank(bProdStageDB)) {//如果数据库中查询不到则初始化
                    bProdStageInfo.setStagePrimaryKey(bProdStageInfo.getProdType()
                            +String.format("%2s", null==bProdStageInfo.getProdCode()?"":bProdStageInfo.getProdCode())+bProdStageInfo.getBaseProdCode()
                            +String.format("%32s", bProdStageInfo.getProdStageCode())
                            +String.format("%2s", bProdStageInfo.getProdStageNum())+bProdStageInfo.getFeeEffectiveDate());
                    bProdStageInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                    bProdStageInfo.setStageStatus(status);
                    bProdStageInfo.setAuditStatus(auditStatus);
                    bProdStageInfo.setLastOprId(user.getId());
                    bProdStageInfo.setLastUpdateTime(lastUpddt);
                    bProdStageInfo.setCreateTime(lastUpddt);
                    bProdStageInfo.setOprId(user.getId());
                    bProdStageInfo.setFeeEffectiveDate(now);
                    bProdStageInfo.setId(null);
                } else {
                    BeanUtils.copyProperties(bProdStageDB, bProdStageInfo);
                    bProdStageInfo.setFeeExpiryDate(BusinessContainer.doomsday);
                    bProdStageInfo.setStageStatus(status);
                    bProdStageInfo.setAuditStatus(auditStatus);
                    bProdStageInfo.setLastOprId(user.getId());
                    bProdStageInfo.setLastUpdateTime(lastUpddt);
                }
                bProdStageInfoService.saveOrUpdate(bProdStageInfo);
            }
        }

        List<BProdAuthCtrl> listDB = bProdAuthCtrlService.getProdAuthCtrlAdd(entity.getInstId(),ProdTypeEnum.PROD.getType(),entity.getBaseProdCode(),entity.getProdCode());
        List<BProdAuthCtrl> listDBDel= Lists.newArrayList();//待删除的数据，需要审核时只从临时表删除
        //查找提交数据中无，数据库有的数据
        for(BProdAuthCtrl bProdAuthCtrlDB : listDB){
            boolean del=true;
            for (BProdAuthCtrl bProdAuthCtrl:entity.getBProdAuthCtrlList()) {
                if(bProdAuthCtrlDB.getInstId().equals(bProdAuthCtrl.getInstId())
                        &&bProdAuthCtrlDB.getProdType().equals(bProdAuthCtrl.getProdType())
                        &&bProdAuthCtrlDB.getBaseProdCode().equals(bProdAuthCtrl.getBaseProdCode())
                        &&bProdAuthCtrlDB.getProdCode().equals(bProdAuthCtrl.getProdCode())
                        &&bProdAuthCtrlDB.getTxnNum().equals(bProdAuthCtrl.getTxnNum())
                        &&bProdAuthCtrlDB.getBizType().equals(bProdAuthCtrl.getBizType())){
                    del=false;
                }
            }
            if(del){//如果需要删除则从正式表取出待删除
                listDBDel.add(bProdAuthCtrlDB);
            }
        }
        if(listDBDel.size()>0){//从正式表删除
            bProdAuthCtrlService.delete(listDBDel);
        }

        for (BProdAuthCtrl bProdAuthCtrl:entity.getBProdAuthCtrlList()){
            BProdAuthCtrl bProdAuthCtrlDB =
                    bProdAuthCtrlService.findByUKAdd(bProdAuthCtrl.getInstId(),ProdTypeEnum.PROD.getType(),bProdAuthCtrl.getBaseProdCode(),bProdAuthCtrl.getProdCode(),bProdAuthCtrl.getTxnNum(),bProdAuthCtrl.getBizType());

            if (Common.isBlank(bProdAuthCtrlDB)) {//如果数据库中查询不到则初始化
                bProdAuthCtrl.setStatus(status);
                bProdAuthCtrl.setAuditStatus(auditStatus);
                bProdAuthCtrl.setLastOprId(user.getId());
                bProdAuthCtrl.setLastUpdateTime(lastUpddt);
                bProdAuthCtrl.setCreateTime(lastUpddt);
                bProdAuthCtrl.setOprId(user.getId());
                bProdAuthCtrl.setProdType(ProdTypeEnum.PROD.getType());
                bProdAuthCtrl.setId(null);
            } else {
                bProdAuthCtrlDB.setTxnGroup(bProdAuthCtrl.getTxnGroup());
                bProdAuthCtrlDB.setTxnNum(bProdAuthCtrl.getTxnNum());
                bProdAuthCtrlDB.setTxnName(bProdAuthCtrl.getTxnName());
                bProdAuthCtrlDB.setBizType(bProdAuthCtrl.getBizType());
//                bProdAuthCtrlService.detach(bProdAuthCtrlDB);
                BeanUtils.copyProperties(bProdAuthCtrlDB, bProdAuthCtrl);
                bProdAuthCtrl.setStatus(status);
                bProdAuthCtrl.setAuditStatus(auditStatus);
                bProdAuthCtrl.setLastOprId(user.getId());
                bProdAuthCtrl.setLastUpdateTime(lastUpddt);
            }
            bProdAuthCtrlService.saveOrUpdate(bProdAuthCtrl);
        }
        return OperationResult.buildSuccessResult("数据保存处理完成", result);
    }

    private void updateProdInfo(BProdInfo entity, String status) {
        entity.setProdStatus(status);
        this.baseMapper.updateProdInfo(entity);
    }


}
